package com.nts.visionworks.core.concurrent;

import java.util.concurrent.Callable;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * 
 * @author Devcken
 * @param <T>
 */
public class ProcessCallable<T> implements Callable<T>
{
	private static final Logger logger = LoggerFactory.getLogger(ProcessCallable.class);
	
	private Process _process;
	
	private String[] _parameters;
	
	public ProcessCallable(String[] parameters)
	{
		this._parameters = parameters;
	}

	@Override
	public T call() throws Exception
	{
		try
		{
			this._process = new ProcessBuilder(_parameters).start();
			
			this._process.waitFor();
		}
		catch (Exception error)
		{
			logger.error(error.getMessage(), error);
		}
		
		return null;
	}
	
	public void shutdownProcess()
	{
		if (this._process != null)
		{
			this._process.destroy();
		}
	}
}